﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using System.Web.Script.Services;

namespace KTSonline.ajax
{
    public partial class login : System.Web.UI.Page
    {
        public System.Collections.Generic.List<KTSonline.TAI_KHOAN> tk = new System.Collections.Generic.List<TAI_KHOAN>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["usercheck"] != null)
            {
                Response.Expires = -1;
                Response.ContentType = "text/plain";

                String user = Request.QueryString["user"];
                KTSonlineDataContext db = new KTSonlineDataContext();
                var rs = db.TAI_KHOANs.Where(tk => tk.username == user);
                if (rs.Count() == 0)
                    Response.Write("TRUE");
                else
                    Response.Write("FALSE");
                Response.End();
            }
            if (Request.QueryString["emailcheck"] != null)
            {
                Response.Expires = -1;
                Response.ContentType = "text/plain";

                String email = Request.QueryString["email"];
                KTSonlineDataContext db = new KTSonlineDataContext();
                var rs = db.TAI_KHOANs.Where(tk => tk.email == email);
                if (rs.Count() == 0)
                    Response.Write("TRUE");
                else
                    Response.Write("FALSE");
                Response.End();
            }
            if (Request.QueryString["logout"] != null)
            {
                Session["user"] = null;
            }
            else if (Request.QueryString["user"] != null && Request.QueryString["pass"] != null)
            {
                KTSonline.KTSonlineDataContext db = new KTSonline.KTSonlineDataContext();
                tk = db.spa_LayTaiKhoan(Request.QueryString["user"], Request.QueryString["pass"]).ToList();
                if (tk.Count > 0)
                    Session["user"] = tk.First();
                else
                    Session["user"] = null;
            }
            else
            {

            }
        }
    }
}
